package ocg.myBatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * Created by chenbo on 2018/5/15.
 */
public class DBLink {

    private static SqlSessionFactoryBuilder sqlSessionFactoryBuilder;
    private static SqlSessionFactory sqlSessionFactory;

    public static void init() throws IOException {
        String resource = "configuration.xml" ;
        Reader reader = Resources.getResourceAsReader(resource);
        sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        sqlSessionFactory = sqlSessionFactoryBuilder.build(reader);

    }

    public static SqlSession getSqlSession(){
        SqlSession sqlSession  = sqlSessionFactory.openSession ();

    }

}
